﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Refugees.Views.Windows
{
    public partial class Uslugies : Window
    {
        Repositories.RecuestRepository recuestRepository = new Repositories.RecuestRepository();
        public Uslugies()
        {
            InitializeComponent();
            if (Repositories.UserRepository.User.role_id != 1)
            {
                NewUslugi.Visibility = Visibility.Hidden;
            }
            if (Repositories.UserRepository.User.role_id != 2)
            {
                ChangeOrganozationColumn.Visibility = Visibility.Collapsed;
                Result.IsReadOnly = true;
            }
            Result.ItemsSource = recuestRepository.GetRecuests(Repositories.ModelRepository.User.Id);
        }

        private void UserClick(object sender, RoutedEventArgs e)
        {
            new Personals().Show();
            Close();
        }

        private void UsliguClick(object sender, RoutedEventArgs e)
        {
            new Uslugies().Show();
            Close();
        }

        private void ContactsClick(object sender, RoutedEventArgs e)
        {
            new ContactNumbers().Show();
            Close();
        }

        private void NewsClick(object sender, RoutedEventArgs e)
        {
            new News().Show();
            Close();
        }

        private void NewUslugaClick(object sender, RoutedEventArgs e)
        {
            new Uslugi().Show();
            Close();
        }

        private void ChangeOrganization(object sender, RoutedEventArgs e)
        {
            var recuest = (sender as Button).DataContext as Models.Recuest;
            if (recuest != null)
            {
                recuest.Organization = Repositories.ModelRepository.User.Organization;
                recuest.IdOrganization = Repositories.ModelRepository.User.organization_id;
                Result.ItemsSource = recuestRepository.GetRecuests(Repositories.ModelRepository.User.Id);
            }
        }

        private void SaveClick(object sender, RoutedEventArgs e)
        {
            if (Repositories.ModelRepository.Save())
            {
                MessageBox.Show("Данные сохранены успешно");
            }
            else
            {
                MessageBox.Show("Данные не сохранены. Повторите попытку позже или проверьте данные");
            }
        }
    }
}
